package com.wms.controller;

import com.wms.dto.StoragePageQueryDTO;
import com.wms.entity.WmsStorage;
import com.wms.result.PageResult;
import com.wms.result.Result;
import com.wms.service.StorageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/storage")
@Slf4j
@Api(tags = "仓库管理模块")
public class StorageController {
    @Autowired
    private StorageService storageService;


    /**
     * 仓库分页查询
     * @param storagePageQueryDTO
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页查询")
    public Result<PageResult> page(@RequestBody StoragePageQueryDTO storagePageQueryDTO){
        PageResult pageResult = storageService.page(storagePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 新增仓库
     * @param storage
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增仓库")
    public Result save(@RequestBody WmsStorage storage){
        storageService.save(storage);
        return Result.success();
    }

    /**
     * 修改仓库
     * @param storage
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改仓库")
    public Result update(@RequestBody WmsStorage storage){
        storageService.update(storage);
        return Result.success();
    }

    /**
     * 批量删除仓库
     * @param ids
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("批量删除仓库")
    public Result delete(@RequestParam List<Long> ids){
        storageService.delete(ids);
        return Result.success();
    }

    @GetMapping("/getAll")
    @ApiOperation("查询所有仓库")
    public Result getAll(){
        List<WmsStorage> storages = storageService.getAll();
        return Result.success(storages);
    }
}
